'''
购物车模块用例
共分为 增删改查
该 case为 添加购物车
'''
import unittest
from common.Base import Base, open_browser
from Page.shopping_process_page import shopping_process
from common.databaseTool import DatabaseTool
import ddt
from common.openExcel import Open_excel
import os
from Page.shoppingcart_page import Shopingcart_page
import hashlib

# 登录页面url
url = "http://localhost:8080/ecshop/user.php"


class Shopingcart_case(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.data = DatabaseTool("168168", "ecshop_db", port=3308)
        sql = f"insert into ecs_users (user_name,password) values ('test','{hashlib.md5(b'111111').hexdigest()}')"
        cls.data.execute_one(sql)

    @classmethod
    def tearDownClass(cls):
        sql = "delete from ecs_users where user_name like '%test%'"
        cls.data.execute_one(sql)

    def setUp(self):
        pass
        # 每一个用例执行前执行 准备测试数据
        op = open_browser()
        self.shop = shopping_process(op)
        self.shop.open_url(url)
        self.shop.input_username("test")
        self.shop.input_password("111111")
        self.shop.click_submit()
        self.shop.click_homepage()

    def tearDown(self):
        # 每一个用例执行后执行 清除环境
        # 关闭浏览器
        self.shop.quit()
        pass

    # # 判断首页 智能相机是否能够加入购物车
    def test_shopping_add_001(self):
        # 点击智能相机商品
        self.shop.click_Smartcamera()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有智能相机
        self.assertEqual(self.shop.in_shopping_cart(), "智能相机", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_002(self):
        # 点击炫彩翻页保护套商品
        self.shop.click_Colorfulflipcover()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有炫彩翻页保护套
        self.assertEqual(self.shop.in_shopping_cart(), "炫彩翻页保护套", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_003(self):
        # 点击平衡车商品
        self.shop.click_Balanceofthecar()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有平衡车
        self.assertEqual(self.shop.in_shopping_cart(), "平衡车", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_004(self):
        # 点击透明超薄软胶保护套商品
        self.shop.click_superProtectivesleeve()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有透明超薄软胶保护套
        self.assertEqual(self.shop.in_shopping_cart(), "透明超薄软胶保护套", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_005(self):
        # 点击运动相机商品
        self.shop.click_Sportscamera()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有运动相机
        self.assertEqual(self.shop.in_shopping_cart(), "运动相机", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_006(self):
        # 点击自拍杆商品
        self.shop.click_Sincetheshaft()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有自拍杆
        self.assertEqual(self.shop.in_shopping_cart(), "自拍杆", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_007(self):
        # 点击随身风扇商品
        self.shop.cilck_Keepthefan()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有随身风扇
        self.assertEqual(self.shop.in_shopping_cart(), "随身风扇", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_008(self):
        # 点击视频商品
        self.shop.click_video()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 判断购物车是否有视频
        self.assertEqual(self.shop.in_shopping_cart(), "视频", msg="用例执行失败商品不在购物车内")

        '''后追加用例 首页添加商品 分类添加商品'''

    def test_shopping_add_035(self):
        # 点击分类
        self.shop.click_goodsclass()
        # 选择第一个商品
        self.shop.click_goods_confirm()
        # 加入购物车
        self.shop.click_goods_confirm()
        # 断言
        self.assertEqual(self.shop.in_shopping_cart(), "学院风简约双肩包", msg="用例执行失败商品不在购物车内")

    def test_shopping_add_036(self):
        # 点击搜索
        self.shop.click_imageField()
        # 选择商品
        self.shop.click_imageField_good()
        # 点击加入购物车
        self.shop.click_goods_confirm()
        # 断言
        self.assertEqual(self.shop.in_shopping_cart(), "视频", msg="用例执行失败商品不在购物车内")
